#include "guint.h"

s16 sintable[] = {
	0x0000, 0x0032, 0x0064, 0x0096, 0x00c9, 0x00fb, 0x012d, 0x0160, 0x0192, 0x01c4,
	0x01f7, 0x0229, 0x025b, 0x028e, 0x02c0, 0x02f2, 0x0324, 0x0357, 0x0389, 0x03bb,
	0x03ee, 0x0420, 0x0452, 0x0484, 0x04b7, 0x04e9, 0x051b, 0x054e, 0x0580, 0x05b2,
	0x05e4, 0x0617, 0x0649, 0x067b, 0x06ad, 0x06e0, 0x0712, 0x0744, 0x0776, 0x07a9,
	0x07db, 0x080d, 0x083f, 0x0871, 0x08a4, 0x08d6, 0x0908, 0x093a, 0x096c, 0x099f,
	0x09d1, 0x0a03, 0x0a35, 0x0a67, 0x0a99, 0x0acb, 0x0afe, 0x0b30, 0x0b62, 0x0b94,
	0x0bc6, 0x0bf8, 0x0c2a, 0x0c5c, 0x0c8e, 0x0cc0, 0x0cf2, 0x0d25, 0x0d57, 0x0d89,
	0x0dbb, 0x0ded, 0x0e1f, 0x0e51, 0x0e83, 0x0eb5, 0x0ee7, 0x0f19, 0x0f4b, 0x0f7c,
	0x0fae, 0x0fe0, 0x1012, 0x1044, 0x1076, 0x10a8, 0x10da, 0x110c, 0x113e, 0x116f,
	0x11a1, 0x11d3, 0x1205, 0x1237, 0x1269, 0x129a, 0x12cc, 0x12fe, 0x1330, 0x1361,
	0x1393, 0x13c5, 0x13f6, 0x1428, 0x145a, 0x148c, 0x14bd, 0x14ef, 0x1520, 0x1552,
	0x1584, 0x15b5, 0x15e7, 0x1618, 0x164a, 0x167b, 0x16ad, 0x16df, 0x1710, 0x1741,
	0x1773, 0x17a4, 0x17d6, 0x1807, 0x1839, 0x186a, 0x189b, 0x18cd, 0x18fe, 0x1930,
	0x1961, 0x1992, 0x19c3, 0x19f5, 0x1a26, 0x1a57, 0x1a88, 0x1aba, 0x1aeb, 0x1b1c,
	0x1b4d, 0x1b7e, 0x1baf, 0x1be1, 0x1c12, 0x1c43, 0x1c74, 0x1ca5, 0x1cd6, 0x1d07,
	0x1d38, 0x1d69, 0x1d9a, 0x1dcb, 0x1dfc, 0x1e2d, 0x1e5d, 0x1e8e, 0x1ebf, 0x1ef0,
	0x1f21, 0x1f52, 0x1f82, 0x1fb3, 0x1fe4, 0x2015, 0x2045, 0x2076, 0x20a7, 0x20d7,
	0x2108, 0x2139, 0x2169, 0x219a, 0x21ca, 0x21fb, 0x222b, 0x225c, 0x228c, 0x22bd,
	0x22ed, 0x231d, 0x234e, 0x237e, 0x23ae, 0x23df, 0x240f, 0x243f, 0x2470, 0x24a0,
	0x24d0, 0x2500, 0x2530, 0x2560, 0x2591, 0x25c1, 0x25f1, 0x2621, 0x2651, 0x2681,
	0x26b1, 0x26e1, 0x2711, 0x2740, 0x2770, 0x27a0, 0x27d0, 0x2800, 0x2830, 0x285f,
	0x288f, 0x28bf, 0x28ee, 0x291e, 0x294e, 0x297d, 0x29ad, 0x29dd, 0x2a0c, 0x2a3c,
	0x2a6b, 0x2a9b, 0x2aca, 0x2af9, 0x2b29, 0x2b58, 0x2b87, 0x2bb7, 0x2be6, 0x2c15,
	0x2c44, 0x2c74, 0x2ca3, 0x2cd2, 0x2d01, 0x2d30, 0x2d5f, 0x2d8e, 0x2dbd, 0x2dec,
	0x2e1b, 0x2e4a, 0x2e79, 0x2ea8, 0x2ed7, 0x2f06, 0x2f34, 0x2f63, 0x2f92, 0x2fc0,
	0x2fef, 0x301e, 0x304c, 0x307b, 0x30a9, 0x30d8, 0x3107, 0x3135, 0x3163, 0x3192,
	0x31c0, 0x31ef, 0x321d, 0x324b, 0x3279, 0x32a8, 0x32d6, 0x3304, 0x3332, 0x3360,
	0x338e, 0x33bc, 0x33ea, 0x3418, 0x3446, 0x3474, 0x34a2, 0x34d0, 0x34fe, 0x352b,
	0x3559, 0x3587, 0x35b5, 0x35e2, 0x3610, 0x363d, 0x366b, 0x3698, 0x36c6, 0x36f3,
	0x3721, 0x374e, 0x377c, 0x37a9, 0x37d6, 0x3803, 0x3831, 0x385e, 0x388b, 0x38b8,
	0x38e5, 0x3912, 0x393f, 0x396c, 0x3999, 0x39c6, 0x39f3, 0x3a20, 0x3a4d, 0x3a79,
	0x3aa6, 0x3ad3, 0x3b00, 0x3b2c, 0x3b59, 0x3b85, 0x3bb2, 0x3bde, 0x3c0b, 0x3c37,
	0x3c64, 0x3c90, 0x3cbc, 0x3ce9, 0x3d15, 0x3d41, 0x3d6d, 0x3d99, 0x3dc5, 0x3df1,
	0x3e1d, 0x3e49, 0x3e75, 0x3ea1, 0x3ecd, 0x3ef9, 0x3f25, 0x3f50, 0x3f7c, 0x3fa8,
	0x3fd3, 0x3fff, 0x402b, 0x4056, 0x4082, 0x40ad, 0x40d8, 0x4104, 0x412f, 0x415a,
	0x4186, 0x41b1, 0x41dc, 0x4207, 0x4232, 0x425d, 0x4288, 0x42b3, 0x42de, 0x4309,
	0x4334, 0x435f, 0x4389, 0x43b4, 0x43df, 0x4409, 0x4434, 0x445f, 0x4489, 0x44b4,
	0x44de, 0x4508, 0x4533, 0x455d, 0x4587, 0x45b1, 0x45dc, 0x4606, 0x4630, 0x465a,
	0x4684, 0x46ae, 0x46d8, 0x4702, 0x472c, 0x4755, 0x477f, 0x47a9, 0x47d2, 0x47fc,
	0x4826, 0x484f, 0x4879, 0x48a2, 0x48cc, 0x48f5, 0x491e, 0x4948, 0x4971, 0x499a,
	0x49c3, 0x49ec, 0x4a15, 0x4a3e, 0x4a67, 0x4a90, 0x4ab9, 0x4ae2, 0x4b0b, 0x4b33,
	0x4b5c, 0x4b85, 0x4bad, 0x4bd6, 0x4bfe, 0x4c27, 0x4c4f, 0x4c78, 0x4ca0, 0x4cc8,
	0x4cf0, 0x4d19, 0x4d41, 0x4d69, 0x4d91, 0x4db9, 0x4de1, 0x4e09, 0x4e31, 0x4e58,
	0x4e80, 0x4ea8, 0x4ed0, 0x4ef7, 0x4f1f, 0x4f46, 0x4f6e, 0x4f95, 0x4fbd, 0x4fe4,
	0x500b, 0x5032, 0x505a, 0x5081, 0x50a8, 0x50cf, 0x50f6, 0x511d, 0x5144, 0x516b,
	0x5191, 0x51b8, 0x51df, 0x5205, 0x522c, 0x5253, 0x5279, 0x52a0, 0x52c6, 0x52ec,
	0x5313, 0x5339, 0x535f, 0x5385, 0x53ab, 0x53d1, 0x53f7, 0x541d, 0x5443, 0x5469,
	0x548f, 0x54b5, 0x54da, 0x5500, 0x5525, 0x554b, 0x5571, 0x5596, 0x55bb, 0x55e1,
	0x5606, 0x562b, 0x5650, 0x5675, 0x569b, 0x56c0, 0x56e5, 0x5709, 0x572e, 0x5753,
	0x5778, 0x579d, 0x57c1, 0x57e6, 0x580a, 0x582f, 0x5853, 0x5878, 0x589c, 0x58c0,
	0x58e5, 0x5909, 0x592d, 0x5951, 0x5975, 0x5999, 0x59bd, 0x59e1, 0x5a04, 0x5a28,
	0x5a4c, 0x5a6f, 0x5a93, 0x5ab7, 0x5ada, 0x5afd, 0x5b21, 0x5b44, 0x5b67, 0x5b8b,
	0x5bae, 0x5bd1, 0x5bf4, 0x5c17, 0x5c3a, 0x5c5d, 0x5c7f, 0x5ca2, 0x5cc5, 0x5ce7,
	0x5d0a, 0x5d2d, 0x5d4f, 0x5d71, 0x5d94, 0x5db6, 0x5dd8, 0x5dfa, 0x5e1d, 0x5e3f,
	0x5e61, 0x5e83, 0x5ea5, 0x5ec6, 0x5ee8, 0x5f0a, 0x5f2c, 0x5f4d, 0x5f6f, 0x5f90,
	0x5fb2, 0x5fd3, 0x5ff4, 0x6016, 0x6037, 0x6058, 0x6079, 0x609a, 0x60bb, 0x60dc,
	0x60fd, 0x611e, 0x613e, 0x615f, 0x6180, 0x61a0, 0x61c1, 0x61e1, 0x6202, 0x6222,
	0x6242, 0x6263, 0x6283, 0x62a3, 0x62c3, 0x62e3, 0x6303, 0x6323, 0x6342, 0x6362,
	0x6382, 0x63a1, 0x63c1, 0x63e0, 0x6400, 0x641f, 0x643f, 0x645e, 0x647d, 0x649c,
	0x64bb, 0x64da, 0x64f9, 0x6518, 0x6537, 0x6556, 0x6574, 0x6593, 0x65b2, 0x65d0,
	0x65ef, 0x660d, 0x662b, 0x664a, 0x6668, 0x6686, 0x66a4, 0x66c2, 0x66e0, 0x66fe,
	0x671c, 0x673a, 0x6757, 0x6775, 0x6792, 0x67b0, 0x67cd, 0x67eb, 0x6808, 0x6825,
	0x6843, 0x6860, 0x687d, 0x689a, 0x68b7, 0x68d4, 0x68f1, 0x690d, 0x692a, 0x6947,
	0x6963, 0x6980, 0x699c, 0x69b9, 0x69d5, 0x69f1, 0x6a0e, 0x6a2a, 0x6a46, 0x6a62,
	0x6a7e, 0x6a9a, 0x6ab5, 0x6ad1, 0x6aed, 0x6b08, 0x6b24, 0x6b40, 0x6b5b, 0x6b76,
	0x6b92, 0x6bad, 0x6bc8, 0x6be3, 0x6bfe, 0x6c19, 0x6c34, 0x6c4f, 0x6c6a, 0x6c84,
	0x6c9f, 0x6cba, 0x6cd4, 0x6cef, 0x6d09, 0x6d23, 0x6d3e, 0x6d58, 0x6d72, 0x6d8c,
	0x6da6, 0x6dc0, 0x6dda, 0x6df3, 0x6e0d, 0x6e27, 0x6e40, 0x6e5a, 0x6e73, 0x6e8d,
	0x6ea6, 0x6ebf, 0x6ed9, 0x6ef2, 0x6f0b, 0x6f24, 0x6f3d, 0x6f55, 0x6f6e, 0x6f87,
	0x6fa0, 0x6fb8, 0x6fd1, 0x6fe9, 0x7002, 0x701a, 0x7032, 0x704a, 0x7062, 0x707a,
	0x7092, 0x70aa, 0x70c2, 0x70da, 0x70f2, 0x7109, 0x7121, 0x7138, 0x7150, 0x7167,
	0x717e, 0x7196, 0x71ad, 0x71c4, 0x71db, 0x71f2, 0x7209, 0x7220, 0x7236, 0x724d,
	0x7264, 0x727a, 0x7291, 0x72a7, 0x72bd, 0x72d4, 0x72ea, 0x7300, 0x7316, 0x732c,
	0x7342, 0x7358, 0x736e, 0x7383, 0x7399, 0x73ae, 0x73c4, 0x73d9, 0x73ef, 0x7404,
	0x7419, 0x742e, 0x7443, 0x7458, 0x746d, 0x7482, 0x7497, 0x74ac, 0x74c0, 0x74d5,
	0x74ea, 0x74fe, 0x7512, 0x7527, 0x753b, 0x754f, 0x7563, 0x7577, 0x758b, 0x759f,
	0x75b3, 0x75c7, 0x75da, 0x75ee, 0x7601, 0x7615, 0x7628, 0x763b, 0x764f, 0x7662,
	0x7675, 0x7688, 0x769b, 0x76ae, 0x76c1, 0x76d3, 0x76e6, 0x76f9, 0x770b, 0x771e,
	0x7730, 0x7742, 0x7754, 0x7767, 0x7779, 0x778b, 0x779d, 0x77af, 0x77c0, 0x77d2,
	0x77e4, 0x77f5, 0x7807, 0x7818, 0x782a, 0x783b, 0x784c, 0x785d, 0x786e, 0x787f,
	0x7890, 0x78a1, 0x78b2, 0x78c3, 0x78d3, 0x78e4, 0x78f4, 0x7905, 0x7915, 0x7925,
	0x7936, 0x7946, 0x7956, 0x7966, 0x7976, 0x7985, 0x7995, 0x79a5, 0x79b5, 0x79c4,
	0x79d4, 0x79e3, 0x79f2, 0x7a02, 0x7a11, 0x7a20, 0x7a2f, 0x7a3e, 0x7a4d, 0x7a5b,
	0x7a6a, 0x7a79, 0x7a87, 0x7a96, 0x7aa4, 0x7ab3, 0x7ac1, 0x7acf, 0x7add, 0x7aeb,
	0x7af9, 0x7b07, 0x7b15, 0x7b23, 0x7b31, 0x7b3e, 0x7b4c, 0x7b59, 0x7b67, 0x7b74,
	0x7b81, 0x7b8e, 0x7b9b, 0x7ba8, 0x7bb5, 0x7bc2, 0x7bcf, 0x7bdc, 0x7be8, 0x7bf5,
	0x7c02, 0x7c0e, 0x7c1a, 0x7c27, 0x7c33, 0x7c3f, 0x7c4b, 0x7c57, 0x7c63, 0x7c6f,
	0x7c7a, 0x7c86, 0x7c92, 0x7c9d, 0x7ca9, 0x7cb4, 0x7cbf, 0x7ccb, 0x7cd6, 0x7ce1,
	0x7cec, 0x7cf7, 0x7d02, 0x7d0c, 0x7d17, 0x7d22, 0x7d2c, 0x7d37, 0x7d41, 0x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0x7ffe, 0x7fff,
};

signed short sins(unsigned short x)
{
	signed short val;

	x >>= 4;

	if (x & 0x400) {
		val = sintable[0x3ff - (x & 0x3ff)];
	} else {
		val = sintable[x & 0x3ff];
	}

	if (x & 0x800) {
		return -val;
	} else {
		return val;
	}
}
